Gerando Grafico Geral
graficos_notas = ggplot() +
geom_boxplot(data=dados_long, aes(x=as.factor(momentos), y=medida_numerica, color=as.factor(momentos)),
alpha=0.5, fill = 'white', show.legend = F) +
geom_point(data=dados_long, aes(x=as.factor(momentos), y=medida_numerica, color=as.factor(momentos)),
alpha=0.5, size=2.5, show.legend = F) +
geom_line(data=dados_long, aes(x=as.factor(momentos), y=medida_numerica, color='grey', group = ID), color='grey',
alpha=0.1, show.legend = F) +
labs(x=NULL, y='Notas da Dor (n)', title=NULL) +
scale_x_discrete(labels=c('Avaliação','Reavaliação')) +
theme(legend.position = "none") + theme_bw() +
facet_grid(~mes)
graficos_notas

#ggsave("Graficos/Boxplot_pareado_por_mes.png", height=15, width=35, units="cm", dpi= 600)
############################################################################
coluna1 = 'reavaliacao_com_diminuicao_do_score_de_dor_em_ate_3_pontos'
grafi1 = df %>%
group_by(mes, !!sym(coluna1)) %>%
summarise(n = n()) %>%
mutate(frequencia = round(n/sum(n)*100, 2)) %>%
ungroup() %>%
filter(!!sym(coluna1) == TRUE) %>%
mutate(coluna = coluna1)
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
coluna2 = 'reavaliacao_em_ate_1_hora'
grafi2 = df %>%
group_by(mes, !!sym(coluna2)) %>%
summarise(n = n()) %>%
mutate(frequencia = round(n/sum(n)*100, 2)) %>%
ungroup() %>%
filter(!!sym(coluna2) == TRUE) %>%
mutate(coluna = coluna2)
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
combined_grafi = bind_rows(grafi1, grafi2)
combined_grafi$texto = paste0(round(combined_grafi$n, 0), ' (', round(combined_grafi$frequencia, 1), '%)')
combined_grafi$mes = factor(combined_grafi$mes, levels = c('Janeiro', 'Fevereiro', 'Março',
'Abril', 'Maio', 'Junho', 'Julho'))
graficos_med = ggplot(combined_grafi,
aes(x=as.factor(coluna), y=frequencia, label=frequencia, fill=as.factor(coluna))) +
geom_col(color="black") +
geom_text(aes(y=frequencia, label = texto, vjust=-0.5)) +
theme_bw() + theme(legend.position = "bottom") + theme(
axis.text.x = element_blank(), # Remove os textos do eixo x
axis.ticks.x = element_blank() # Remove os ticks do eixo x
) +
scale_y_continuous(limits = c(0, 100), breaks=seq(from = 0, to = 100, by = 20)) +
scale_fill_manual(values = c('#00bbf9','#00f5d4'),
labels = c('Reavaliação com Diminuição do Score em até 3 pontos', 'Reavaliação em até 1H')) +
labs(x=NULL, y="Frequency (%)", title =NULL, fill=NULL) +
facet_grid(~mes)
graficos_med

#ggsave("Graficos/Contagem_por_mes.png", height=15, width=35, units="cm", dpi= 600)
# Combinar os gráficos com um tÃtulo geral
combined_plot <- graficos_notas / graficos_med +
plot_annotation(title = "Geral",
theme = theme(plot.title = element_text(hjust = 0.5)))
print(combined_plot)

ggsave("Graficos/Geral.png", height=25, width=35, units="cm", dpi= 600)
Gerando Grafico para cada setor
for (i in dados_long_bckp$setor %>% as.factor() %>% levels()){
print(i)
df = df_bckp %>% filter(setor == i)
dados_long = dados_long_bckp %>% filter(setor == i)
graficos_notas = ggplot() +
geom_boxplot(data=dados_long, aes(x=as.factor(momentos), y=medida_numerica, color=as.factor(momentos)),
alpha=0.5, fill = 'white', show.legend = F) +
geom_point(data=dados_long, aes(x=as.factor(momentos), y=medida_numerica, color=as.factor(momentos)),
alpha=0.5, size=2.5, show.legend = F) +
geom_line(data=dados_long, aes(x=as.factor(momentos), y=medida_numerica, color='grey', group = ID), color='grey',
alpha=0.1, show.legend = F) +
labs(x=NULL, y='Notas da Dor (n)', title=NULL) +
scale_x_discrete(labels=c('Avaliação','Reavaliação')) +
theme(legend.position = "none") + theme_bw() +
facet_grid(~mes)
#graficos_notas
#ggsave("Graficos/Boxplot_pareado_por_mes.png", height=15, width=35, units="cm", dpi= 600)
############################################################################
coluna1 = 'reavaliacao_com_diminuicao_do_score_de_dor_em_ate_3_pontos'
grafi1 = df %>%
group_by(mes, !!sym(coluna1)) %>%
summarise(n = n()) %>%
mutate(frequencia = round(n/sum(n)*100, 2)) %>%
ungroup() %>%
filter(!!sym(coluna1) == TRUE) %>%
mutate(coluna = coluna1)
coluna2 = 'reavaliacao_em_ate_1_hora'
grafi2 = df %>%
group_by(mes, !!sym(coluna2)) %>%
summarise(n = n()) %>%
mutate(frequencia = round(n/sum(n)*100, 2)) %>%
ungroup() %>%
filter(!!sym(coluna2) == TRUE) %>%
mutate(coluna = coluna2)
combined_grafi = bind_rows(grafi1, grafi2)
combined_grafi$texto = paste0(round(combined_grafi$n, 0), ' (', round(combined_grafi$frequencia, 1), '%)')
combined_grafi
graficos_med = ggplot(combined_grafi,
aes(x=as.factor(coluna), y=frequencia, label=frequencia, fill=as.factor(coluna))) +
geom_col(color="black") +
geom_text(aes(y=frequencia, label = texto, vjust=-0.5)) +
theme_bw() + theme(legend.position = "bottom") + theme(
axis.text.x = element_blank(), # Remove os textos do eixo x
axis.ticks.x = element_blank() # Remove os ticks do eixo x
) +
scale_y_continuous(limits = c(0, 100), breaks=seq(from = 0, to = 100, by = 20)) +
scale_fill_manual(values = c('#00bbf9','#00f5d4'),
labels = c('Reavaliação com Diminuição do Score em até 3 pontos', 'Reavaliação em até 1H')) +
labs(x=NULL, y="Frequency (%)", title =NULL, fill=NULL) +
facet_grid(~mes)
#graficos_med
#ggsave("Graficos/Contagem_por_mes.png", height=15, width=35, units="cm", dpi= 600)
# Combinar os gráficos com um tÃtulo geral
combined_plot <- graficos_notas / graficos_med +
plot_annotation(title = i,
theme = theme(plot.title = element_text(hjust = 0.5)))
print(combined_plot)
ggsave(paste0("Graficos/",i,".png"), plot = combined_plot, height=25, width=35, units="cm", dpi= 600)
}
## [1] "1º andar Endoscopia"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## [1] "1º Andar UI Adulto"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "1º Andar UI Infantil"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "1º Andar UTI Adulto"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "1º Andar UTI Infantil"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "2º Andar Hospital UI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "2º Andar UTI Adulto"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "4° andar UI Hospital"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "4º A UTI Ped B"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "4º Andar UTI Adulto"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "4º Andar UTI Ped A"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "5º Andar Ala B UI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "5º Andar Ala A UI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "6º Andar Ala B UI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "6º andar UICB"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "6º Andar UTI Adulto Ala A"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "6º Andar UTI Adulto Ala B"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "6º Andar UTI Cardiológica"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Aguardando Vaga P.S. (MRB)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Aguardando Vaga P.S. Infantil"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Ala Pré e Pós Operatório 4º andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Ambulatório (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Centro Cirúrgico"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Centro Cirurgico- RPA"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Centro Cirúrgico - Ala Pré e Pós Operatório 4º andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Centro Cirúrgico (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Endoscopia Digestiva e Respiratória (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Fisioterapia (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Fonoaudiologia (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Laboratório de Anatomia - Morumbi"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Adulto- 1º Andar UI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Adulto - 1º Andar UTI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Adulto - Aguardando Vaga (MRB)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Adulto (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Infantil- 1º Andar UTI"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Infantil - Aguardando Vaga"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Pronto Socorro Infantil (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "Repouso Pronto Socorro - Adulto"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "RPA Centro Cirurgico"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT- 1º andar Endoscopia"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT- Endoscopia Digestiva e Respiratória (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT- Laboratório de Anatomia - Morumbi"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT Análises ClÃnicas (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT Cardiologia (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT Raio-X e Arco Cirúrgico (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT Ressonancia (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT Tomografia (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "SADT Ultrassonografia Geral (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UI- 2º Andar Hospital"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UI- 5º Andar Ala B"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UI- 5º Andar Ala A"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UI- 6º Andar Ala B"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UI- Fisioterapia (MR)"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UTI Adult- 4º Andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UTI Adulto Ala A- 6º Andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UTI Adulto Ala B- 6º Andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UTI Cardiológica- 6º Andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UTI Ped A- 4º Andar"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

## [1] "UTI Ped B- 4º A"
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.
## `summarise()` has grouped output by 'mes'. You can override using the `.groups`
## argument.

